<% layout('/layouts/default.html', {title: '产品系列型号管理', libs: ['validate','dataGrid']}){ %>
<div class="main-content">
	<div class="box box-main">
		<div class="box-header with-border">
			<div class="box-title">
				<i class="fa fa-list-alt"></i> ${text(tgSeries.isNewRecord ? '新增产品系列型号' : '编辑产品系列型号')}
			</div>
			<div class="box-tools pull-right">
				<button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i></button>
			</div>
		</div>
		<#form:form id="inputForm" model="${tgSeries}" action="${ctx}/tg/tgSeries/save" method="post" class="form-horizontal"
		  onSubmit="return app.beforeSubmit(this)">
			<div class="box-body">
				<div class="form-unit">${text('基本信息')}</div>
				<#form:hidden path="id"/>
				<#form:hidden path="isModified"/>
				<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required ">*</span> ${text('产品系列')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="fgSeries" maxlength="20" class="form-control required" />
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('系列说明')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="fgDesc" maxlength="40" class="form-control"/>
							</div>
						</div>
					</div>
				</div>
				<h4 class="form-unit">${text('产品型号')}</h4>
				<div class="ml10 mr10">
					<table id="thModelDataGrid"></table>
					<div id="thModelDataGridPage"></div>
					<% if (hasPermi('tg:tgSeries:edit')){ %>
						<a href="#" id="thModelDataGridAddRowBtn" class="btn btn-primary btn-sm mt10 mb10"><i class="fa fa-plus"></i> ${text('增行')}</a>
					<% } %>
				</div>
			</div>
			<div class="box-footer">
				<div class="row">
					<div class="col-sm-offset-2 col-sm-10">
						<% if (hasPermi('tg:tgSeries:edit')){ %>
							<button type="submit" class="btn btn-sm btn-primary" id="btnSubmit"><i class="fa fa-check"></i> ${text('保 存')}</button>&nbsp;
						<% } %>
						<button type="button" class="btn btn-sm btn-default" id="btnCancel" onclick="js.closeCurrentTabPage()"><i class="fa fa-reply-all"></i> ${text('关 闭')}</button>
					</div>
				</div>
			</div>
		</#form:form>
	</div>
</div>



<% } %>
<script>
	mFieldsToUpper="fgSeries,fhModel,fhCustModel".split(",");
	/*function genModelCates(){
		var lvRet={};
		var lvTmp=${@DictUtils.getDictListJson('th_cat')};
		for (var i=0;i<lvTmp.length;i++){
			lvRet[lvTmp[i].dictValue]=lvTmp[i].dictLabel;
		}
		return lvRet;
	}
	function genModelFlag(){
		var lvRet={};
		var lvTmp=${@DictUtils.getDictListJson('fh_ref_flag')};
		for (var i=0;i<lvTmp.length;i++){
			lvRet[lvTmp[i].dictValue]=lvTmp[i].dictLabel;
		}
		return lvRet;
	}
	var mCates=genModelCates();
	var mFlags=genModelFlag();*/

	//var mLastRow=0;
	//从表分页的查询form
$("#detSearchForm").attr("action","${ctx}/tg/tgSeries/listChildData")
		.attr("data-order-by","fh_model");
$("#detSearchForm #id").val("${tgSeries.id}");

//初始化产品型号DataGrid对象
$("#thModelDataGrid").dataGrid({

	/*by rock 6/Jul/2019 data: ${toJson(tgSeries.thModelList)},
	datatype: "local", // 设置本地数据
	*/
	searchForm: $("#detSearchForm"), //by rock 6/Jul/2019

	autoGridHeight: function(){return 'auto'}, // 设置自动高度
	
	// 设置数据表格列
	columnModel: [
		{header:'状态', name:'status', editable:true, hidden:true},
		{header:'主键', name:'id', editable:true, hidden:true},
		{header:'isModified', name:'isModified', editable:true, hidden:true},
		{header:'${text("tg的id")}', name:'fhTgId.id', editable:true, hidden:true},
		{header:'${text("产品型号")}', name:'fhModel', width:150, editable:true, edittype:'text', editoptions:{'maxlength':'25', 'class':'form-control required'}
		/*,
			formatter: function(val, obj, row, act){
				return "<a href=#>{0}</a>".format(row.fhModel);
			}*/
		},
		{header:'${text("型号说明")}', name:'fhDesc', width:150, editable:true, edittype:'text', editoptions:{'maxlength':'40', 'class':'form-control'}},
		{header:'${text("类型")}', name:'fhCategory', width:100, 
			editable:true, edittype:'select', editoptions:{'class':'form-control required',
				items: $.merge([{dictLabel:'&nbsp;',dictValue:''}], ${@DictUtils.getDictListJson('th_cat')}),
				itemLabel: 'dictLabel', itemValue: 'dictValue', dataInit: function(element){
					$(element).select2().on("change",function(){$(this).resetValid()});
				}
			}/*,formatter: function(val, obj, row, act){
				return mCates[row.fhCategory];
			}*/
		},
		{header:'${text("客户型号")}', name:'fhCustModel', width:150, editable:true, edittype:'text', editoptions:{'maxlength':'25', 'class':'form-control required'}},
		{header:'${text("参考标志")}', name:'fhRefFlag', width:100, 
			editable:true, edittype:'select', editoptions:{'class':'form-control',
				items: $.merge([{dictLabel:'&nbsp;',dictValue:''}], ${@DictUtils.getDictListJson('fh_ref_flag')}),
				itemLabel: 'dictLabel', itemValue: 'dictValue', dataInit: function(element){
					$(element).select2().on("change",function(){$(this).resetValid()});
				}
			}/*,formatter: function(val, obj, row, act){
				return mFlags[row.fhRefFlag];
			}*/
		},
		{header:'${text("操作")}', name:'actions', width:80, sortable:false, fixed:true, formatter: function(val, obj, row, act){
			var actions = [];
			if (val == 'new'){
				actions.push('<a href="#" onclick="js.confirm(\'${text("你确认要删除这条数据吗？")}\', function(){$(\'#thModelDataGrid\').dataGrid(\'delRowData\',\''+obj.rowId+'\')});return false;"><i class="fa fa-trash-o"></i></a>&nbsp;');
			}else{
				//actions.push('<a href="#" onclick="js.confirm(\'${text("你确认要停用这条数据吗？")}\', function(){$(\'#thModelDataGrid\').dataGrid(\'setRowData\',\''+obj.rowId+'\',null,{display:\'none\'});$(\'#'+obj.rowId+'_status\').val(\''+Global.STATUS_DISABLE+'\');});return false;"><i class="glyphicon glyphicon-ban-circle"></i></a>&nbsp;');
				if (row.status == Global.STATUS_NORMAL){
					var lvScript='<a title="${text("停用这条数据")}" href="#" onclick="return app.gridRowStatusAction(this,\'${text("你确认要停用这条数据吗？")}\',\'#thModelDataGrid\',\''+obj.rowId+'\');"><i class="glyphicon glyphicon-ban-circle"></i></a>&nbsp;';
					actions.push(lvScript);
				}
				if (row.status == Global.STATUS_DISABLE){
					//actions.push('<a href="${ctx}/tg/tgSeries/enable-child?id='+row.id+'" class="btnList" title="${text("启用产品系列型号")}" data-confirm="${text("确认要启用该产品型号吗？")}"><i class="glyphicon glyphicon-ok-circle"></i></a>&nbsp;');
					var lvScript='<a title="${text("启用这条数据")}"  href="#" onclick="return app.gridRowStatusAction(this,\'${text("你确认要启用这条数据吗？")}\',\'#thModelDataGrid\',\''+obj.rowId+'\');"><i class="glyphicon glyphicon-ok-circle"></i></a>&nbsp;';
					actions.push(lvScript);
				}
				//actions.push('<a href="#" onclick="js.confirm(\'${text("你确认要删除这条数据吗？")}\', function(){$(\'#thModelDataGrid\').dataGrid(\'setRowData\',\''+obj.rowId+'\',null,{display:\'none\'});$(\'#'+obj.rowId+'_status\').val(\''+Global.STATUS_DELETE+'\');});return false;"><i class="fa fa-trash-o"></i></a>&nbsp;');
				var lvDelScript='<a title="${text("删除这条数据")}"  href="#" onclick="return app.gridRowStatusAction(this,\'${text("你确认要删除这条数据吗？")}\',\'#thModelDataGrid\',\''+obj.rowId+'\',\'1\');"><i class="fa fa-trash-o"></i></a>&nbsp;';
				actions.push(lvDelScript);
			}
			return actions.join('');
		}, editoptions: {defaultValue: 'new'}}
	],
	
	// 编辑表格参数
	editGrid: true,				// 是否是编辑表格
	editGridInitRowNum: 1,		// 编辑表格的初始化新增行数
	//viewrecords : true,
	editGridAddRowBtn: $('#thModelDataGridAddRowBtn'),	// 子表增行按钮
	editGridAddRowInitData: {id: '', status: Global.STATUS_NORMAL},	// 新增行的时候初始化的数据
	
	// 编辑表格的提交数据参数
	editGridInputFormListName: 'thModelList', // 提交的数据列表名
	editGridInputFormListAttrs: 'status,id,isModified,fhTgId.id,fhModel,fhDesc,fhPhoto,fhCategory,fhCustModel,fhRefFlag,updateBy,updateDate,fhMdlOsVer,fhMdlBiosVer,fhMdlEcVer,fhMdlTouchpadVer,fhMdlCpu,fhMdlRam,fhMdlSsd,fhMdlRuninTime,fhMdlDeviceinfo,fhMdlOther,fhStatus,fhSerial,fhPrice,fhGenericname,createBy,createDate', // 提交数据列表的属性字段
	
	// 加载成功后执行事件
	ajaxSuccess: function(data){
		
	},
	/*onSelectRow : function(id) {
		if (id && id !== mLastRow) {
			jQuery('#thModelDataGrid').jqGrid('restoreRow', mLastRow);
			jQuery('#rowed3').jqGrid('editRow', id, true);
			mLastRow = id;
		}
	},*/
	afterInsertRow:function(rowid ,rowdata ,rowelem){
		//console.log('afterInsertRow');
		//console.log(rowid,rowdata,rowelem);
		//关键字转大写
 		setTimeout(function(){
 			app.setUpperCaseGridRow(rowid);
			app.setHookChangeEvent(rowid,rowdata);
 		},500); //必须要延时,因为这个事件发生时还没有input 创建
	},
	gridComplete:function(){
		/*if ($("#inputForm #id").val()){
			setTimeout(function(){
				$("#fgSeries").attr("readOnly","readOnly");
				$("#inputForm input").filter("input[name='fhModel']").attr("readOnly","readOnly");
			},800);
		}*/
	}
});


</script>
<script>

	//mFieldsToUpper.push("fgSeries");
$("#inputForm").validate({
	submitHandler: function(form){
		js.ajaxSubmitForm($(form), function(data){
			js.showMessage(data.message);
			if(data.result == Global.TRUE){
				js.closeCurrentTabPage(function(contentWindow){
					contentWindow.page();
				});
			}
		}, "json");
    }
});
</script>

